package com.syswin.lhztest.controller;

import com.github.pagehelper.PageHelper;
import com.syswin.lhztest.model.User;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:lhz
 * @date:2018/12/1 20:40
 */
@RestController
public class PersonController {
//	@Autowired
//	private PersonService personService;

	@GetMapping("/getAllPerson")
	public String getAllPerson(Model model, @RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum) {
		PageHelper.startPage(pageNum, 5);
		List list = new ArrayList();
		Map map =  new HashMap();
//		PageInfo<Person> pageInfo = new PageInfo<Person>(list);
//		model.addAttribute("pageInfo",pageInfo);
		return "list";
	}


	@RequestMapping("/login")
	public String login(@Valid User user, BindingResult result) {
		if (result.hasErrors()) {
			List<ObjectError> errorList = result.getAllErrors();
			for (ObjectError error : errorList) {
				System.out.println(error.getDefaultMessage());
			}
			return "error";
		}

		return "success";
	}
}
